package com.service.yzj.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.service.yzj.config.ApiResponse;
import com.service.yzj.dto.boss.CustomListRequest;
import com.service.yzj.dto.boss.OrderListRequest;
import com.service.yzj.model.pages.boss.CustomDetailPage;
import com.service.yzj.model.pages.boss.CustomListPage;
import com.service.yzj.model.pages.boss.OrderDetailPage;
import com.service.yzj.model.pages.boss.OrderListPage;
import com.service.yzj.service.BossService;


/**
 * controller for wx mini program
 */
@RestController
@RequestMapping("/api/boss")
public class BossController {

  final BossService bossService;
  final Logger logger;

  public BossController(
    @Autowired BossService bossService
  ) {
    this.bossService = bossService;
    this.logger = LoggerFactory.getLogger(WXController.class);
  }

  /**
   * 获取首页数据
   */
  @GetMapping(value = "/home")
  ApiResponse getHome() {
    logger.info("/api/wx/home get");

    return ApiResponse.ok(null);
  }


  /**
   * 获取客户列表
   */
  @PostMapping(value = "/customer/list")
  ApiResponse postCustomList(@RequestBody CustomListRequest request) {

    CustomListPage page = bossService.getCustomers(request);
    return ApiResponse.ok(page);
  }

  /**
   * 获取客户详情
   */
  @GetMapping(value = "/customer/detail")
  ApiResponse getCustomDetail(@RequestParam long userId) {
    logger.info("/api/boss/customer/detail get");
    CustomDetailPage page = bossService.getCustomerById(userId);
    return ApiResponse.ok(page);
  }


  /**
   * 获取订单列表
   */
  @PostMapping(value = "/order/list")
  ApiResponse postOrderList(@RequestBody OrderListRequest request) {
    logger.info("/api/boss/order/list get");

    OrderListPage page = bossService.getOrderList(request);
    return ApiResponse.ok(page);
  }

  /**
   * 获取订单详情
   */
  @GetMapping(value = "/order/detail")
  ApiResponse getOrderDetail(@RequestParam long orderId) {
    logger.info("/api/boss/order/detail get");
    OrderDetailPage page = bossService.getOrderById(orderId);
    return ApiResponse.ok(page);
  }
}

